package com.polaris.live.adapter.luckybag

import android.view.LayoutInflater
import android.view.ViewGroup
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.StringUtils
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.R
import com.polaris.live.R.drawable
import com.polaris.live.common.adapter.BaseAdapter
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.databinding.AdapterLuckyBagDetailBinding
import com.polaris.live.resp.back_resp.luckybag.LuckyBagDetailResp
import com.polaris.live.translation.R.string
import com.polaris.live.utils.CommonUtils.toBoolean
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * LuckyBagDetailAdapter
 *
 * @author Created by lucas on 2024/6/11 13:34
 */
class LuckyBagDetailAdapter :
    BaseAdapter<LuckyBagDetailResp.LuckyBagReceive, LuckyBagDetailAdapter.LuckyBagDetailBaseHolder>(0) {

    override fun onCreateDefViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): LuckyBagDetailBaseHolder {
        return LuckyBagDetailBaseHolder(
            AdapterLuckyBagDetailBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    override fun convert(holder: LuckyBagDetailBaseHolder, item: LuckyBagDetailResp.LuckyBagReceive) {
        holder.binding.apply {
            holder.binding.apply {
                avAvatar.setImageUrl(item.userBasic.avatar, item.userBasic.userId)
                avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.userBasic.avatarFrame))
                if (UserManager.getUserId() == item.userBasic.userId) {
                    tvNickname.text = StringUtils.getString(string.you)
                    tvNickname.setTextColor(ColorUtils.getColor(R.color.luckyReceiveYourSelfTextColor))
                } else {
                    tvNickname.text = item.userBasic.nickname
                    tvNickname.setTextColor(ColorUtils.getColor(R.color.colorPrimaryText))
                }
                tvCoin.text = item.coins.toString()
                tvTime.text = TimeUtils.millis2String(item.createTime, "MM/dd HH:mm")
                if (item.bombStatus.toBoolean()) {
                    ivBackColor.setImageResource(drawable.lucky_history_bomb_back)
                    ivItemTypeIcon.setImageResource(drawable.lucky_history_bomb_icon)
                } else {
                    if (item.luckyStatus.toBoolean()) {
                        ivBackColor.setImageResource(drawable.lucky_history_bag_back)
                        ivItemTypeIcon.setImageResource(drawable.lucky_history_bag_icon)
                    } else {
                        ivBackColor.setImageResource(0)
                        ivItemTypeIcon.setImageResource(0)
                    }
                }
            }
        }
    }

    class LuckyBagDetailBaseHolder(
        val binding: AdapterLuckyBagDetailBinding,
    ) : BaseViewHolder(binding.root)

}